package com.sheep.classroompie.service;

import com.sheep.classroompie.entity.Comment;
import com.sheep.classroompie.entity.Homework;
import com.sheep.classroompie.entity.SubmitHomework;
import com.sheep.classroompie.repository.HomeworkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;


@Service
public class HomeworkServiceImpl implements HomeworkService{
  @Autowired
  HomeworkRepository homeworkRepository;
  @Override
  public List<Homework> selectHomeworksByCourseId(String courseId) {
    return homeworkRepository.selectHomeworksByCourseId(courseId);
  }

  @Override
  public Homework selectHomeworksById(Integer id) {
    return homeworkRepository.selectHomeworksById(id);
  }

  @Override
  public Boolean addHomework(Homework homework) {
    Date date = new Date();  //获取当前时间
    Date start = homework.getCreateTime();
    Date end = homework.getEndTime();
    int result = date.compareTo(start);
    int result1 = date.compareTo(end);
    if(result1 < 0){
      if(result < 0){
        homework.setStatus("未开始");
      }else{
        homework.setStatus("进行中");
      }
    }else{
      homework.setStatus("已结束");
    }
    return homeworkRepository.addHomework(homework);
  }

  @Override
  public Boolean deleteHomework(Integer homeworkId) {
    return homeworkRepository.deleteHomework(homeworkId);
  }

  @Override
  public void addSubmitHomework(SubmitHomework submitHomework) {
    homeworkRepository.addSubmitHomework(submitHomework);
  }

  @Override
  public SubmitHomework selectSubmitHomeworkById(SubmitHomework submitHomework) {
    return homeworkRepository.selectSubmitHomeworkById(submitHomework);
  }

  @Override
  public Boolean uploadFile(SubmitHomework submitHomework) {
    return homeworkRepository.uploadFile(submitHomework);
  }

  @Override
  public void submit(SubmitHomework submitHomework) {
    homeworkRepository.submit(submitHomework);
  }

  @Override
  public List<SubmitHomework> selectSubmitHomeworkByStatus(SubmitHomework submitHomework) {
    return homeworkRepository.selectSubmitHomeworkByStatus(submitHomework);
  }

  @Override
  public void scoring(SubmitHomework submitHomework) {
    homeworkRepository.scoring(submitHomework);
  }

  @Override
  public void updateHomework(Homework homework) {
    homeworkRepository.updateHomework(homework);
  }

  @Override
  public void addComment(Comment comment) {
    homeworkRepository.addComment(comment);
  }

  @Override
  public List<Comment> queryComments(Comment comment) {
    return homeworkRepository.queryComments(comment);
  }
}
